
Page({

  /**
   * 页面的初始数据
   */
  data: {
    leftHeight: 1,
    rightHeight: 0,
    dataList:[
      {
        bigImg: '/static/swiper/1.jpg',
        bigName: '北京三日游最全攻略，让我们成功拿下。北京三日游最全攻略，让我们成功拿下。北京三日游最全攻略，让我们成功拿下。',
        infoImg: '/static/no-avatar.png',
        infoName: '千秋岁',
        likeImg: '/static/found/guanzhu.png',
        likeNum: 503,
        tag: 'left',
      }, 
      {
        bigImg: '/static/swiper/1.jpg',
        bigName: '让我们成功拿下。',
        infoImg: '/static/no-avatar.png',
        infoName: '千秋岁',
        likeImg: '/static/found/guanzhu.png',
        likeNum: 43,
        tag: 'left',
      }, 
      {
        bigImg: '/static/swiper/1.jpg',
        bigName: '北京三日游最全攻略，让我们成功拿下。',
        infoImg: '/static/no-avatar.png',
        infoName: '千秋岁',
        likeImg: '/static/found/guanzhu.png',
        likeNum: 2,
        tag: 'right',
      }, 
      {
        bigImg: '/static/swiper/1.jpg',
        bigName: '北京三日游最全攻略，让我们成功拿下。加油加油加加油！！！！',
        infoImg: '/static/no-avatar.png',
        infoName: '千秋岁',
        likeImg: '/static/found/guanzhu.png',
        likeNum: 1120,
        tag: 'left',
      }, 
      {
        bigImg: '/static/swiper/1.jpg',
        bigName: '北京三日游最全攻略，让我们成功拿下。',
        infoImg: '/static/no-avatar.png',
        infoName: '千秋岁',
        likeImg: '/static/found/guanzhu.png',
        likeNum: 548,
        tag: 'right',
      }
    ]
  },
  _dataList() {
    let that = this

    let leftHeight = that.data.leftHeight;
    let rightHeight = that.data.rightHeight;
    let dataList = [].concat(that.data.dataList);

    for (let i = 0; i < 20; i++) {
      const type = Math.floor(Math.random() * 1000);
      let tag = "";
      // 添加元素/计算高度
      if (leftHeight > rightHeight) {
        tag = 'right';
        rightHeight += 240; // item高度
        if (type > 500) {
          leftHeight -= 30; // 高度差
        }
      } else {
        tag = 'left';
        leftHeight += 240; // item高度
        if (type < 500 ) {
          rightHeight -= 30; // 高度热
        }
      }
      dataList.push({
        bigImg: '/static/swiper/1.jpg',
        bigName: '北京三日游最全攻略，让我们成功拿下。',
        infoImg: '/static/no-avatar.png',
        infoName: '千秋岁',
        likeImg: '/static/found/guanzhu.png',
        likeNum: type,
        tag,
      });
    }
    that.setData({ dataList, rightHeight, leftHeight });
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({
      dataList: [],
    })
    wx.stopPuliDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this._dataList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})